﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Permision.DAL;
using Tools;

namespace Permision.BLL
{
    /// <summary>
    /// Summary description for ActionsRolesBase
    /// </summary>
    public class Per_ActionsManagerBase
    {
        public Per_ActionsManagerBase()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public void InsertUpdate(Per_ActionsEntity item)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", item.Id));
            ls.Add(new SqlParameter("@Name", item.Name));
            ls.Add(new SqlParameter("@Description", item.Description));
            SqlParameter[] sqlparam = ls.ToArray();
            Tools.SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_InsertUpdatePer_Actions", sqlparam);
        }
        public void InsertUpdate(string Id, string Name, string Description)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            ls.Add(new SqlParameter("@Name", Name));
            ls.Add(new SqlParameter("@Description", Description));
            SqlParameter[] sqlparam = ls.ToArray();
            Tools.SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_InsertUpdatePer_Actions", sqlparam);
        }
        public void Delete(string Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            Tools.SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_DeletePer_Actions", sqlparam);
        }
        public Per_ActionsEntity GetPer_ActionsEntity(DataRow dr)
        {
            Per_ActionsEntity item = new Per_ActionsEntity();            
            item.Id = dr["Id"].ToString();              
            item.Name = dr["Name"].ToString();              
            item.Description = dr["Description"].ToString();              
            return item;
        }
        
        public DataTable SelectOneRDT(string Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            return Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_Actions", sqlparam);
        }
        public Per_ActionsEntity SelectOne(string Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_Actions", sqlparam);
            if(dt!=null && dt.Rows.Count>0)
                return GetPer_ActionsEntity(dt.Rows[0]);
            return null;
        }
        public DataTable SelectAllRDT()
        {
            return Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ActionsAll", null);
        }
        public List<Per_ActionsEntity> SelectAll()
        {
            List<Per_ActionsEntity> lsresult= new List<Per_ActionsEntity>();
            DataTable dt =  Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ActionsAll", null);
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetPer_ActionsEntity(dt.Rows[i]));            
            return lsresult;
        }
    }
}

